package com.spvs.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spvs.common.log.annotation.Log;
import com.spvs.common.log.enums.BusinessType;
import com.spvs.common.security.annotation.RequiresPermissions;
import com.spvs.system.domain.FileVersion;
import com.spvs.system.service.IFileVersionService;
import com.spvs.common.core.web.controller.BaseController;
import com.spvs.common.core.web.domain.AjaxResult;
import com.spvs.common.core.utils.poi.ExcelUtil;
import com.spvs.common.core.web.page.TableDataInfo;

/**
 * 文件修改及版本控制Controller
 *
 * @author supervision
 * @date 2024-12-12
 */
@RestController
@RequestMapping("/version")
public class FileVersionController extends BaseController
{
    @Autowired
    private IFileVersionService fileVersionService;

    /**
     * 查询文件修改及版本控制列表
     */
    @RequiresPermissions("system:version:list")
    @GetMapping("/list")
    public TableDataInfo list(FileVersion fileVersion)
    {
        startPage();
        List<FileVersion> list = fileVersionService.selectFileVersionList(fileVersion);
        return getDataTable(list);
    }

    /**
     * 导出文件修改及版本控制列表
     */
    @RequiresPermissions("system:version:export")
    @Log(title = "文件修改及版本控制", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FileVersion fileVersion)
    {
        List<FileVersion> list = fileVersionService.selectFileVersionList(fileVersion);
        ExcelUtil<FileVersion> util = new ExcelUtil<FileVersion>(FileVersion.class);
        util.exportExcel(response, list, "文件修改及版本控制数据");
    }

    /**
     * 获取文件修改及版本控制详细信息
     */
    @RequiresPermissions("system:version:query")
    @GetMapping(value = "/{versionId}")
    public AjaxResult getInfo(@PathVariable("versionId") Long versionId)
    {
        return success(fileVersionService.selectFileVersionByVersionId(versionId));
    }

    /**
     * 新增文件修改及版本控制
     */
    @RequiresPermissions("system:version:add")
    @Log(title = "文件修改及版本控制", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FileVersion fileVersion)
    {
        return toAjax(fileVersionService.insertFileVersion(fileVersion));
    }

    /**
     * 修改文件修改及版本控制
     */
    @RequiresPermissions("system:version:edit")
    @Log(title = "文件修改及版本控制", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FileVersion fileVersion)
    {
        return toAjax(fileVersionService.updateFileVersion(fileVersion));
    }

    /**
     * 删除文件修改及版本控制
     */
    @RequiresPermissions("system:version:remove")
    @Log(title = "文件修改及版本控制", businessType = BusinessType.DELETE)
	@DeleteMapping("/{versionIds}")
    public AjaxResult remove(@PathVariable Long[] versionIds)
    {
        return toAjax(fileVersionService.deleteFileVersionByVersionIds(versionIds));
    }
}
